package com.dianping.cat.home.service.client.transform;

import com.dianping.cat.home.service.client.IEntity;
import com.dianping.cat.home.service.client.IVisitor;
import com.dianping.cat.home.service.client.entity.ClientReport;
import com.dianping.cat.home.service.client.entity.Domain;
import com.dianping.cat.home.service.client.entity.Method;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private ClientReport m_clientReport;


  public DefaultMerger() {}

  public DefaultMerger(ClientReport clientReport) {
/*  21 */     this.m_clientReport = clientReport;
/*  22 */     this.m_objs.push(clientReport);
  }


/*  26 */   public ClientReport getClientReport() { return this.m_clientReport; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeClientReport(ClientReport to, ClientReport from) { to.mergeAttributes(from); }



/*  44 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  48 */   protected void mergeMethod(Method to, Method from) { to.mergeAttributes(from); }



  public void visitClientReport(ClientReport from) {
/*  53 */     ClientReport to = (ClientReport)this.m_objs.peek();

/*  55 */     mergeClientReport(to, from);
/*  56 */     visitClientReportChildren(to, from);
  }

  protected void visitClientReportChildren(ClientReport to, ClientReport from) {
/*  60 */     for (Domain source : from.getDomains().values()) {
/*  61 */       Domain target = to.findDomain(source.getId());

/*  63 */       if (target == null) {
/*  64 */         target = new Domain(source.getId());
/*  65 */         to.addDomain(target);
      }

/*  68 */       this.m_objs.push(target);
/*  69 */       source.accept(this);
/*  70 */       this.m_objs.pop();
    }
  }


  public void visitDomain(Domain from) {
/*  76 */     Domain to = (Domain)this.m_objs.peek();

    mergeDomain(to, from);
/*  79 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
/*  83 */     for (Method source : from.getMethods().values()) {
/*  84 */       Method target = to.findMethod(source.getId());

/*  86 */       if (target == null) {
/*  87 */         target = new Method(source.getId());
/*  88 */         to.addMethod(target);
      }

/*  91 */       this.m_objs.push(target);
/*  92 */       source.accept(this);
/*  93 */       this.m_objs.pop();
    }
  }


  public void visitMethod(Method from) {
/*  99 */     Method to = (Method)this.m_objs.peek();

/* 101 */     mergeMethod(to, from);
/* 102 */     visitMethodChildren(to, from);
  }

  protected void visitMethodChildren(Method to, Method from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/service/client/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */